

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Store;
using SubSonic.Utilities;

namespace JTC.MiniCommerce.Web {
  public partial class _default : System.Web.UI.Page {

    #region Member Variables

    int pageId = 0;
    Store.Page page;
    protected HtmlMeta htmlMetaKeywords = new HtmlMeta();
    protected HtmlMeta htmlMetaDescription = new HtmlMeta();

    #endregion

    #region Page Events

    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event to initialize the page.
    /// </summary>
    /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
    protected override void OnInit(EventArgs e) {
      pageId = Utility.GetIntParameter("pageId");
      if (pageId > 0) {
        page = new Store.PageController().FetchByID(pageId)[0];
      }
      else {
        page = new Store.PageController().FetchDefaultPage();
      }

      htmlMetaKeywords.Attributes.Add("name", "keywords");
      htmlMetaKeywords.Attributes.Add("content", page.Keywords);
      Page.Header.Controls.Add(htmlMetaKeywords);

      htmlMetaDescription.Attributes.Add("name", "description");
      htmlMetaDescription.Attributes.Add("content", page.Description);
      Page.Header.Controls.Add(htmlMetaDescription);

      Page.Title = string.Format("{0} :: {1}", Master.SiteSettings.SiteName, page.Title);

      analyticsPlaceHolder.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode(Master.SiteSettings.Analytics)));

      contentPlaceHolder.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode(page.Content)));

      base.OnInit(e);
    }

    protected void Page_Load(object sender, EventArgs e) {
    }

    #endregion

  }
}
